/**
 * 
 */
package leetCode;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;

/**
 * @author zhong
 *
 */
public class BitwiseORsofSubarrays {
	public int subarrayBitwiseORs(int[] A) {
		Queue<Integer>[] queue = new Queue[2];
		queue[0] = new LinkedList<>();
		queue[1] = new LinkedList<>();
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < A.length; i++) {
			queue[0].add(A[i]);
			set.add(A[i]);
		}
		for (int i = 1; i < A.length; i++) {
			for (int j = 0; j < A.length - i; j++) {
				int a = queue[(i - 1) % 2].poll();
				int b = queue[(i - 1) % 2].peek();
				int c = a | b;
				queue[i % 2].add(c);
				set.add(c);
			}
			queue[(i - 1) % 2].poll();
		}
		return set.size();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] A = { 0 };
		System.out.println(new BitwiseORsofSubarrays().subarrayBitwiseORs(A));
	}

}
